package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.mapper.FileDataLogMapper;
import com.ruoyi.system.mapper.FileDataMapper;
import com.ruoyi.system.mapper.PersonnelInformationUserMapper;
import com.ruoyi.system.mapper.PersonnelInformationUserSigninMapper;
import com.ruoyi.system.service.PersonnelInformationUserService;
import com.ruoyi.system.service.fileDataService;
import org.apache.commons.compress.utils.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.stereotype.Service;
import org.springframework.util.ClassUtils;

import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.Date;
import java.util.List;

/**
 * 用户 业务层处理
 * 
 * @author ruoyi
 */
@Service
public class PersonnelInformationUserImpl implements PersonnelInformationUserService
{
    private static final Logger log = LoggerFactory.getLogger(PersonnelInformationUserImpl.class);

    @Autowired
    private PersonnelInformationUserMapper personnelInformationUserMapper;
    @Autowired
    private PersonnelInformationUserSigninMapper personnelInformationUserSigninMapper;


    @Override
    public List<PersonnelInformationUser> selectFileDataList(PersonnelInformationUser fileData) {
        return personnelInformationUserMapper.selectFileDataList(fileData);
    }

    @Override
    public int insertFileData(PersonnelInformationUser personnelInformationUser) {
          return personnelInformationUserMapper.insert(personnelInformationUser);
    }

    @Override
    public int deleteUserByIds(Integer id) {
        return personnelInformationUserMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int editSave(PersonnelInformationUser personnelInformationUser) {
        return personnelInformationUserMapper.updateByPrimaryKeySelective(personnelInformationUser);
    }

    @Override
    public void insertList(List<PersonnelInformationUser> list) {
        personnelInformationUserMapper.insertList(list);
    }
    @Override
    public PersonnelInformationUser getWorknumber(String worknumber) {
        return personnelInformationUserMapper.getWorknumber(worknumber);
    }

    @Override
    public void addaddSignin(List<PersonnelInformationUserSignin> list) {
        personnelInformationUserSigninMapper.addaddSignin(list);
    }

    @Override
    public List<PersonnelInformationUserSignin> getPersonnelInformationUser() {
        return personnelInformationUserSigninMapper.getPersonnelInformationUser();
    }

    @Override
    public void updateSigninState(String batchNumber, String state) {
        personnelInformationUserSigninMapper.updateSigninState(batchNumber,state);
    }

    @Override
    public List<PersonnelInformationUserSignin> getPersonnelInformationUserlist(PersonnelInformationUserSignin personnelinformationusersignin) {
        return personnelInformationUserSigninMapper.getPersonnelInformationUserlist(personnelinformationusersignin);
    }

    @Override
    public int deletePersonnelInformationUserSignin(String batchNumber) {
       int  s=personnelInformationUserSigninMapper.deletePersonnelInformationUserSignin(batchNumber);
       return s;

    }

    @Override
    public List<PersonnelInformationUserSignin> getSigninObj(String batchNumber) {
        return personnelInformationUserSigninMapper.getSigninObj(batchNumber);
    }


    @Override
    public void downLoadTemplate(HttpServletResponse response) {
        // 模板名称
        String templateName = "工作人员.xls";
        OutputStream out = null;
        InputStream input = null;
        try {
            input = ClassUtils.getDefaultClassLoader().getResourceAsStream("static/" + templateName);
            response.setCharacterEncoding("UTF-8");
            response.setHeader("content-Type", "application/vnd.ms-excel");
            response.setHeader("Content-Disposition",
                               "attachment;filename=" + new String((templateName).getBytes(), "iso-8859-1"));
            response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
            out = response.getOutputStream();
            byte[] buffer = new byte[1024]; // 缓冲区
            int bytesToRead = -1;
            // 通过循环将读入内容输出到浏览器中
            while ((bytesToRead = input.read(buffer)) != -1) {
                out.write(buffer, 0, bytesToRead);
            }
        } catch (IOException e) {
            throw new RuntimeException("模板下载失败");
        } finally {
            IOUtils.closeQuietly(input);
            IOUtils.closeQuietly(out);
        }
    }


}
